﻿
namespace N_dimenslArr
{
    using System;
    using System.Collections.Generic;
    using System.Diagnostics;
    using System.Linq;
    using System.Text;
    using Tao.FreeGlut;
    using Tao.OpenGl;
    using Tao.Platform;

    public class Link : GeoLink
    {
        public Link()
        {
            this.From = new double[] { 0, 0 };
            this.To = new double[] { 1, 1 };
        }

        public Link(double[] from, double[] to)
        {
            Debug.Assert(from.Length > 0, "from.Length > 0");
            Debug.Assert(to.Length > 0, "to.Length > 0");
            this.From = from;
            this.To = to;
            this.Status = false;
        }

        public override void Render(double zoom)
        {
          if (zoom < 2)
          {
            Gl.glPushAttrib(Gl.GL_POINT_BIT);

            if (this.Status)
            {
              Gl.glColor4f(1.0f, 0, 0, 1.0f);
              Gl.glPointSize(16.0f);
              Gl.glBegin(Gl.GL_POINTS);
              Gl.glVertex3d(this.From[0], this.From[1], 0);
              Gl.glEnd();
            }

            Gl.glPopAttrib();
           }        
          else 
          {
            Gl.glPushAttrib(Gl.GL_LINE_BIT);
            Gl.glPushAttrib(Gl.GL_COLOR);

            if (this.Status)
            {
              Gl.glLineWidth(2.0f);
              Gl.glColor4f(1.0f, 0, 0, 0.8f);
            }
            else
            {
              Gl.glLineWidth(1.0f);
              Gl.glColor4f(0, 0, 1.0f, 0.4f);
            }

            Gl.glBegin(Gl.GL_LINES);

            Gl.glVertex3d(this.From[0], this.From[1], 0);
            Gl.glVertex3d(this.To[0], this.To[1], 0);

            Gl.glLineWidth(3);
            Gl.glColor4f(0, 0, 1.0f, 0.3f);

            Gl.glVertex3d(this.From[0], this.From[1], 0);
            Gl.glVertex3d(this.To[0], this.To[1], 0);
            Gl.glColor4f(0, 0, 1.0f, 0.25f);

            Gl.glVertex3d(this.From[0], this.From[1] + shift, 0);
            Gl.glVertex3d(this.To[0], this.To[1] + shift, 0);

            Gl.glVertex3d(this.From[0] + shift, this.From[1], 0);
            Gl.glVertex3d(this.To[0] + shift, this.To[1], 0);

            Gl.glVertex3d(this.From[0] - shift, this.From[1], 0);
            Gl.glVertex3d(this.To[0] - shift, this.To[1], 0);

            Gl.glVertex3d(this.From[0], this.From[1] - shift, 0);
            Gl.glVertex3d(this.To[0], this.To[1] - shift, 0);

            Gl.glEnd();
          }
            
        }
    }
}
